package com.example.microserviceorderservice.Controller;

import com.example.microserviceorderservice.Service.OrderServiceImpl;
import com.example.microserviceorderservice.entity.Order;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@EnableAutoConfiguration
public class OrderController {
    @Autowired
    private OrderServiceImpl orderService;

    @GetMapping(value = "/getOrderById/{id}")
    @HystrixCommand(fallbackMethod = "fallbackInfo")
    public List<Order> getOrderById(@PathVariable int id){
        return orderService.getOrderById(id);
    }
    @GetMapping(value = "/getOrderByUserName/{userName}")
    @HystrixCommand(fallbackMethod = "fallbackInfo")
    public List<Order> getOrderByUserName(@PathVariable String userName){
        return orderService.getOrderByUserName(userName);
    }

    public List<Order> fallbackInfo(@PathVariable int id){
        List<Order> list = new ArrayList<>();
        return list;
    }

}
